import com.lqe.Utils.MybatisUtils;
import com.lqe.mapper.UserMapper;
import com.lqe.pojo.Role;
import com.lqe.pojo.User;
import org.apache.ibatis.session.SqlSession;
import org.junit.Test;

import javax.management.relation.RoleList;
import java.util.ArrayList;
import java.util.List;

public class Mytest {

    @Test
    public void insertUser(){
        SqlSession sqlsession = MybatisUtils.getSession();

        UserMapper mapper = sqlsession.getMapper(UserMapper.class);
        User user = new User(null, "韩湘子", 22);
        mapper.insertUser(user);
        sqlsession.commit();
        sqlsession.close();

    }

    @Test
    public void deleteUserById(){
        SqlSession sqlsession = MybatisUtils.getSession();

        UserMapper mapper = sqlsession.getMapper(UserMapper.class);
        mapper.deleteUserById(112);
        sqlsession.commit();
        sqlsession.close();

    }

    @Test
    public void updateUser(){
        SqlSession sqlsession = MybatisUtils.getSession();

        UserMapper mapper = sqlsession.getMapper(UserMapper.class);
        User user = new User(5,"周七",22);
        mapper.updateUser(user);
        sqlsession.commit();
        sqlsession.close();

    }

   @Test
   public void queryUserById(){
       SqlSession sqlsession = MybatisUtils.getSession();

       UserMapper mapper = sqlsession.getMapper(UserMapper.class);
       User user = mapper.queryUserById(116);
       System.out.println(user);
       sqlsession.close();
   }

    @Test
    public void queryAllUser(){
        SqlSession sqlsession = MybatisUtils.getSession();

        UserMapper mapper = sqlsession.getMapper(UserMapper.class);
        List<User> users = mapper.queryAllUser();
        for (User user:
             users) {
            System.out.println(user);
        }
        sqlsession.close();
    }


}
